import { updateComponent } from "./components"
import mountElement from "./mountElement"

export default function diffComponent(virtualDOM, oldComponent, oldEl, container) {
    if (isSameComponent(virtualDOM, oldComponent)) {
        updateComponent(virtualDOM, oldComponent, oldEl, container)
    } else {
        mountElement(virtualDOM, container, oldEl)
    }
}

export function isSameComponent(virtualDOM, oldComponent) {
    return oldComponent && virtualDOM.type === oldComponent.constructor
}
